import request from "@/utils/request.ts";
import type {RoleResponseData,RoleData} from './type.ts'
import {MenuResponseData} from "./type.ts";
enum API{
    ALL_ROLE_URL='/admin/acl/role/',//获取全部角色
    ADD_ROLE_URL='/admin/acl/role/save',//添加职位
    UPDATE_ROLE_URL='/admin/acl/role/update',//更新职位
    ALL_PERMISSION_URL='/admin/acl/permission/toAssign/',//获取全部的菜单与按钮的数据
    SET_PERMISSION_URL='/admin/acl/permission/doAssign/',//分配角色
    REMOVE_ROLE_URL='/admin/acl/role/remove/',//删除角色
}
/**
 * 获取全部角色
 * @param page
 * @param limit
 * @param roleName
 */
export const reqAllRoleList = (page:number,limit:number,roleName:string) => {
  return request.get<any,RoleResponseData>(API.ALL_ROLE_URL+`${page}/${limit}/?roleName=${roleName}`)
}
/**
 * 添加或更新职位
 * @param data
 */
export const reqAddOrUpdateRole = (data:RoleData) => {
  if(data.id){
      return request.put<any>(API.UPDATE_ROLE_URL,data)
  }else {
      return request.post<any>(API.ADD_ROLE_URL,data)
  }
}
/**
 * 获取权限
 * @param roleId
 */
export const reqAllMenuList = (roleId:number) => {
  return request.get<any,MenuResponseData>(API.ALL_PERMISSION_URL+roleId)
}
/**
 *分配角色
 * @param roleId
 * @param permission
 */
export const reqSetPermission = (roleId:number,permission:number[]) => {
  return request.post(API.SET_PERMISSION_URL+`?roleId=${roleId}&permissionId=${permission}`)
}
/**
 * 删除角色
 * @param roleId
 */
export const reqRemoveRole = (roleId:number) => {
  return request.delete<any,any>(API.REMOVE_ROLE_URL+roleId)
}